<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="回复内容" prop="content">
        <el-input
          v-model="queryParams.content"
          placeholder="请输入回复内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="针对性别" prop="atSex">
        <el-select v-model="queryParams.atSex" placeholder="请选择针对性别" clearable
                   size="small">
          <el-option
            v-for="dict in atSexOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['chatnotify:autogreet:add']">
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['chatnotify:autogreet:remove']">
          删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="回复内容" align="center" prop="content" min-width="400"/>
      <el-table-column label="针对性别" align="center" prop="atSex" width="400"
                       :formatter="atSexFormat"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="400">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['chatnotify:autogreet:edit']">
            修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['chatnotify:autogreet:remove']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"/>

    <add-or-update v-show="open" @on-close="open=false" ref="addOrUpdate"></add-or-update>
  </div>
</template>

<script>
  import {
    listAutogreet,
    getAutogreet,
    delAutogreet,
    exportAutogreet
  } from "@/api/chatnotify/autogreet";
  import mixinViewModule from '@/mixins/view-module'
  import AddOrUpdate from './add-or-update'

  export default {
    name: "Autogreet",
    mixins: [mixinViewModule],
    components: {AddOrUpdate},
    data() {
      return {
        mixinViewModuleOptions: {
          getDetailsURL: getAutogreet,// 查询详情实体
          getDataListURL: listAutogreet, // 数据列表接口，API地址
          deleteURL: delAutogreet, // 删除接口，API地址
          deleteIsBatchKey: 'id', // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
          exportURL: exportAutogreet // 导出接口，API地址
        },
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 针对性别 1=男,2=女字典
        atSexOptions: [],
        // 查询参数
        queryParams: {
          content: null, atSex: null,
          orderByColumn: 't.id',
          isAsc: 'desc'
        }
      }
        ;
    },
    created() {
      this.getList();
      let _this = this;
      this.getDicts("sys_user_sex").then(response => {
        this.atSexOptions = response.data;
        _this.$refs.addOrUpdate.atSexOptions = response.data
      });
    },
    methods: {
      // 针对性别 1=男,2=女字典翻译
      atSexFormat(row, column) {
        return this.selectDictLabel(this.atSexOptions, row.atSex);
      },
      //打开dislog前执行
      onOpenHandleDialog() {

      },
      //打开删除前执行
      onHandleDetails(data, type) {
        if (type == this.$formType.edit) {
          this.$refs.addOrUpdate.form = data.data
        }
      },
      //开始查询列表的时候
      onStartQuery() {

      },
      //开始重制查询前执行
      onResetQuery() {

      }
    }
  };
</script>
